/*
* 文件：IOSTool.cs
* 作者：王阳
* 时间：2019-5-20
* 描述：iOS平台工具
*/
using System.IO;
using System.Runtime.InteropServices;
using UnityEngine;

namespace UnityX
{
    public class IOSTool
    {
#if UNITY_IOS && !UNITY_EDITOR
        [DllImport("__Internal")]
        private static extern void _HapticLight();
        [DllImport("__Internal")]
        private static extern void _HapticMedium();
        [DllImport("__Internal")]
        private static extern void _HapticHeavy();

        [DllImport("__Internal")]
        private static extern void _CopyImageToPhotosAlbum(string path);
        [DllImport("__Internal")]
        private static extern void _CopyVideoToPhotosAlbum(string path);
#endif

        /// <summary>
        /// 触觉反馈弱
        /// </summary>
        public static void HapticLight()
        {
#if UNITY_IOS && !UNITY_EDITOR
        _HapticLight();
#endif
        }
        /// <summary>
        /// 触觉反馈中
        /// </summary>
        public static void HapticMedium()
        {
#if UNITY_IOS && !UNITY_EDITOR
        _HapticMedium();
#endif
        }
        /// <summary>
        /// 触觉反馈强
        /// </summary>
        public static void HapticHeavy()
        {
#if UNITY_IOS && !UNITY_EDITOR
        _HapticHeavy();
#endif
        }

        /// <summary>
        /// 保存图片到相册
        /// </summary>
        /// <param name="name"></param>
        /// <param name="data"></param>
        public static void SaveImageToPhotosAlbum(string name, byte[] data)
        {
#if UNITY_IOS && !UNITY_EDITOR
        string path = Application.persistentDataPath + "/" + name;
        File.WriteAllBytes(path, data);
        _CopyImageToPhotosAlbum(path);
#endif
        }
        /// <summary>
        /// 拷贝图片到相册
        /// </summary>
        /// <param name="path"></param>
        public static void CopyImageToPhotosAlbum(string path)
        {
#if UNITY_IOS && !UNITY_EDITOR
        _CopyImageToPhotosAlbum(path);
#endif
        }
        /// <summary>
        /// 保存视频到相册
        /// </summary>
        /// <param name="name"></param>
        /// <param name="data"></param>
        public static void SaveVideoToPhotosAlbum(string name, byte[] data)
        {
#if UNITY_IOS && !UNITY_EDITOR
        string path = Application.persistentDataPath + "/" + name;
        File.WriteAllBytes(path, data);
        _CopyVideoToPhotosAlbum(path);
#endif
        }
        /// <summary>
        /// 拷贝视频到相册
        /// </summary>
        /// <param name="path"></param>
        public static void CopyVideoToPhotosAlbum(string path)
        {
#if UNITY_IOS && !UNITY_EDITOR
        _CopyVideoToPhotosAlbum(path);
#endif
        }
    }
}